<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=emulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<link rel="stylesheet" href="${ctx}/css/sapar.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/common.css" />
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/sapar.js"></script>
<script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
<title>回收数量修改</title>
</head>

<body>
    <div id="saper-container">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>回收数量修改</h2>
            </div>
			<div class="subfiled-content">
	            <form class="saper-form" id="dataForm" >
	                <div class="kv-item clearfix">
	                    <label><span class="impInfo">*</span>科室：</label>
	                    <div class="kv-item-content">
							<p>${depName}</p>
	                        <%--<input type="text" placeholder="交接人" class="txt_required" name="huishouJiaojierenTiaoma" value="${huishou.huishouJiaojierenTiaoma}">--%>
	                    </div>
	                </div>

					<div class="kv-item clearfix">
						<label><span class="impInfo">*</span>包名：</label>
						<div class="kv-item-content">
							<p>${packageName}</p>
							<%--<input type="text" placeholder="回收人" class="txt_required" name="huishouHuishourenTiaoma" value="${huishou.huishouHuishourenTiaoma}">--%>
						</div>
					</div>

					<div class="kv-item clearfix">
						<label><span class="impInfo">*</span>数量：</label>
						<div class="kv-item-content">
							<input id="packageNum" type="number" max="${num}" placeholder="数量" class="txt_required" name="num" value="${num}">
						</div>
					</div>





					<div class="kv-item clearfix">
						<input type="hidden" name="huishouLiushui" id="huishouLiushui" value="${huishouLiushui}"/>
					</div>

	                <div class="kv-item clearfix">
	                    <label>回收人：</label>
	                    <div class="kv-item-content">
	                        <input type="text" placeholder="回收人" name="huishouHuishourenTiaoma" id="huishouHuishourenTiaoma" value="${huishouren}">
	                    </div>
	                </div>

					<div class="kv-item clearfix">
						<label>交接人：</label>
						<div class="kv-item-content">
							<input type="text" placeholder="交接人" name="huishouJiaojierenTiaoma" id="huishouJiaojierenTiaoma" value="${jiaojieren}">
						</div>
					</div>
	                <%----%>
	                <%--<div class="kv-item clearfix">--%>
	                    <%--<label><span class="impInfo">*</span>备注：</label>--%>
	                    <%--<div class="kv-item-content">--%>
	                        <%--<input type="text" placeholder="备注" class="txt_required" name="huishouBeizhu" value="${huishou.huishouBeizhu}">--%>
	                    <%--</div>--%>
	                <%--</div>--%>

	                <div class="buttons">
	                    <a href="javascript:;" class="sapar-btn sapar-btn-recom">确定</a>
	                    <%--<input name="huishouLiushui" type="hidden" value="${huishou.huishouLiushui}">--%>
	                </div>
	            </form>
            </div>
        </div>
        <div id="saper-ft"></div>
    </div>
    
</body>

<script type="text/javascript">

	var data =${data};

$(function(){
	$(".sapar-btn-recom").click(function(){
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		 var btn = true;
		 debugger
		 $(".txt_required").each(function(){
			 if($(this).val() == ''){
				 btn = false;
				 layer.msg("必填项不为空");
				 return false;
			 }
		 });
		 if(btn){
		     var num = $("#packageNum").val();
		     var packageNum = data.length;
		     if(num>packageNum){
		         num = packageNum;
			 }else if(num<0){
		         num = 0;
			 }
			 num = packageNum-num;
			 if(num>=1){
                 var data2 = data.slice(0,num);
                 console.log(num);
                 $.ajax({
                     type: "POST",
                     data:{"packageList":JSON.stringify(data2)},
                     url:"${ctx}/recover/recoverDel",
                     error: function(request) {
                         layer.alert("网络故障，请稍后再试!");
                     },
                     success: function(data) {
                         if(data.status==true){
                             layer.alert("保存成功");
                             parent.layer.close(index);
                         }else{
                             layer.msg(data.msg);
                         }
                     }
                 });
             }else if(num == 0){
                 $.ajax({
                     type: "POST",
                     data:$('.saper-form').serialize(),
                     url:"${ctx}/recover/recoverSave.do",
                     error: function(request) {
                         layer.alert("网络故障，请稍后再试!");
                     },
                     success: function(data) {
                         if(data.status==true){
                             parent.callbackData();
                             parent.layer.close(index);

                         }else{
                             layer.msg(data.msg);
                         }
                     }
                 });
             }

		 }
	});
});

</script>
</html>